package com.ejoysoft.wlanyz.business;

import com.ejoysoft.auth.MD5;
import com.ejoysoft.common.*;
import com.ejoysoft.common.exception.UserUnitIdException;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import java.util.Vector;
import java.util.HashMap;
import java.util.Date;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;

/**
 * Created by IntelliJ IDEA.
 * User: feiwj
 * Date: 2005-9-1
 * Time: 9:12:43
 * To change this template use Options | File Templates.
 */
public class Testpjmanage {
    private Globa globa;
    private DbConnect db;

    //���췽��
    public Testpjmanage() {
    }

    public Testpjmanage(Globa globa) {
        this.globa = globa;
        db = globa.db;
    }

    //���췽��
    public Testpjmanage(Globa globa, boolean b) {
        this.globa = globa;
        db = globa.db;
        if (b) globa.setDynamicProperty(this);
    }

    String strTableName = "wlan_task_projects";
    
    //增加用户
    public boolean add(String strProjectNote,String strProjectName  ) {
        String strSql = "";
        strProjectId = UID.getID();
        try {
        	//把用户信息写入数据库
            strSql = "INSERT INTO " + strTableName + "  (strProjectId, strProjectName, strProjectNote,strCreator, dtCreatDate) VALUES (?,?,?,?,to_date(?,'yyyy-MM-dd hh24:mi:ss'))";
            db.prepareStatement(strSql);
            db.setString(1, strProjectId);
            db.setString(2, strProjectName);
            db.setString(3, strProjectNote);
            db.setString(4, globa.loginName);
            db.setString(5, Format.getDateTime());
   
            if (db.executeUpdate() > 0) {
                Globa.logger0("增加测试项", globa.loginName, globa.loginIp, strSql, "任务管理", globa.userSession.getStrDepart());
                return true;
            } else
                return false;
        } catch (Exception e) {
            System.out.println("增加用户信息时出错！！");
            e.printStackTrace();
            return false;
        }
    }

   

    //ɾ删除部门用户部门联系表中的一条数据
    public boolean delete(String where) {
        try {
            String sql = "DELETE FROM " + strTableName + "  ".concat(where);
            db.executeUpdate(sql);
            return true;
        } catch (Exception ee) {
            ee.printStackTrace();
            return false;
        }
    }
    
 
    public boolean update(String strProjectId,String strProjectName,String strProjectNote) {
        try {
        	String strSql = "UPDATE  " + strTableName + "  SET  strProjectName = ?, strProjectNote = ?, strCreator = ?, dtCreatDate = to_date(?,'yyyy-MM-dd hh24:mi:ss')  WHERE strProjectId=? ";
        	System.out.println("kkkkkkkkkk"+strProjectId+"kkkkkk"+strProjectName+"kkkkkkk"+strProjectNote);
        	
            db.prepareStatement(strSql);
            db.setString(1, strProjectName);
            db.setString(2, strProjectNote);
            db.setString(3, globa.loginName);
            db.setString(4, Format.getDateTime());
            db.setString(5, strProjectId);
            db.executeUpdate();
            Globa.logger0("修改测试项信息", globa.loginName, globa.loginIp, strSql, "任务管理", globa.userSession.getStrDepart());
            return true;
        } catch (Exception e) {
            System.out.println("修改测试项信息时出错：" + e);
            return false;
        }
    }

  //详细显示单条记录
    public Testpjmanage show(String where) {
        try {
            String strSql = "select * from  " + strTableName + "  ".concat(where);
            ResultSet rs = db.executeQuery(strSql);
            if (rs != null && rs.next())
                return load(rs, true);
            else
                return null;
        } catch (Exception ee) {
            return null;
        }
    }
   
  //记录集转化为对象
   
  //查询符合条件的记录总数
    public int getCount(String where) {
        int count = 0;
        try {
            String sql = "SELECT count(strProjectId) FROM " + strTableName + "  ";
            if (where.length() > 0) {
                where = where.toLowerCase();
                if (where.indexOf("order") > 0)
                    where = where.substring(0, where.lastIndexOf("order"));
                sql = String.valueOf(sql) + String.valueOf(where);
            }
            ResultSet rs = db.executeQuery(sql);
            if (rs.next())
                count = rs.getInt(1);
            rs.close();
            return count;
        } catch (Exception ee) {
            ee.printStackTrace();
            return count;
        }
    }

  //列表记录集
	public Vector<Testpjmanage> list(String where, int startRow, int rowCount) {
		Vector<Testpjmanage> beans = new Vector<Testpjmanage>();
        try {
            String sql = "SELECT *  FROM  " + strTableName + " ";
            if (where.length() > 0)
                sql = String.valueOf(sql) + String.valueOf(where);
            Statement s = db.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            if (startRow != 0 && rowCount != 0)
                s.setMaxRows((startRow + rowCount) - 1);
            ResultSet rs = s.executeQuery(sql);
            if (rs != null && rs.next()) {
                if (startRow != 0 && rowCount != 0)
                    rs.absolute(startRow);
                do {
                	Testpjmanage theBean = new Testpjmanage();
                    theBean = load(rs, false);
                    beans.addElement(theBean);
                } while (rs.next());
            }
            rs.close();
            s.close();
        } catch (Exception ee) {
            ee.printStackTrace();
        }
        return beans;
    }

	 public Testpjmanage load(ResultSet rs, boolean isView) {
	    	Testpjmanage theBean = new Testpjmanage();
	        try {
	            theBean.setStrProjectId(rs.getString("strProjectId"));
	            theBean.setStrProjectName(rs.getString("strProjectName"));
	            theBean.setStrProjectNote(rs.getString("strProjectNote"));
	            theBean.setStrCreator(rs.getString("strCreator"));
	            theBean.setDtCreatDate(rs.getString("dtCreatDate"));
	           

	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return theBean;
	    }
	 public Vector<Testpjmanage> list1(String where, int startRow, int rowCount) {
			Vector<Testpjmanage> beans = new Vector<Testpjmanage>();
	        try {
	            String sql = "SELECT distinct (strProjectName)  FROM  " + strTableName + " ";
	            if (where.length() > 0)
	                sql = String.valueOf(sql) + String.valueOf(where);
	            Statement s = db.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
	            if (startRow != 0 && rowCount != 0)
	                s.setMaxRows((startRow + rowCount) - 1);
	            ResultSet rs = s.executeQuery(sql);
	            if (rs != null && rs.next()) {
	                if (startRow != 0 && rowCount != 0)
	                    rs.absolute(startRow);
	                do {
	                	Testpjmanage theBean = new Testpjmanage();
	                    theBean = load1(rs, false);
	                    beans.addElement(theBean);
	                } while (rs.next());
	            }
	            rs.close();
	            s.close();
	        } catch (Exception ee) {
	            ee.printStackTrace();
	        }
	        return beans;
	    }

		 public Testpjmanage load1(ResultSet rs, boolean isView) {
		    	Testpjmanage theBean = new Testpjmanage();
		        try {
		            theBean.setStrProjectName(rs.getString("strProjectName"));
		           

		        } catch (Exception e) {
		            e.printStackTrace();
		        }
		        return theBean;
		    }


    public Testpjmanage(String strProjectId,String strProjectName, String strProjectNote,String strCreator,String dtCreatDate) {
        this.strProjectId = strProjectId;
        this.strProjectName = strProjectName;
        this.strProjectNote = strProjectNote;
        this.strCreator = strCreator;
        this.dtCreatDate = dtCreatDate;
    }

    private String strProjectId;
    private String strProjectName;
    private String strProjectNote;
    private String strCreator;
    private String dtCreatDate;
    
    
    
    
    public String getStrProjectId() {
		return strProjectId;
	}

	public void setStrProjectId(String strProjectId) {
		this.strProjectId = strProjectId;
	}

	public String getStrProjectName() {
		return strProjectName;
	}

	public void setStrProjectName(String strProjectName) {
		this.strProjectName = strProjectName;
	}

	public String getStrProjectNote() {
		return strProjectNote;
	}

	public void setStrProjectNote(String strProjectNote) {
		this.strProjectNote = strProjectNote;
	}

	public String getStrCreator() {
		return strCreator;
	}

	public void setStrCreator(String strCreator) {
		this.strCreator = strCreator;
	}

	public String getDtCreatDate() {
		return dtCreatDate;
	}

	public void setDtCreatDate(String dtCreatDate) {
		this.dtCreatDate = dtCreatDate;
	}

	
    
   

    

    
}
